home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
thesrc10.zip
/
GETCH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-11
|
9KB
|
253 lines
/*
* This software is Copyright (c) 1989, 1990, 1991 by Patrick J. Wolfe.
*
* Permission is hereby granted to copy, distribute or otherwise
* use any part of this package as long as you do not try to make
* money from it or pretend that you wrote it. This copyright
* notice must be maintained in any copy made.
*
* Use of this software constitutes acceptance for use in an AS IS
* condition. There are NO warranties with regard to this software.
* In no event shall the author be liable for any damages whatsoever
* arising out of or in connection with the use or performance of this
* software. Any use of this software is at the user's own risk.
*
* If you make modifications to this software that you feel
* increases it usefulness for the rest of the community, please
* email the changes, enhancements, bug fixes as well as any and
* all ideas to me. This software is going to be maintained and
* enhanced as deemed necessary by the community.
*
* Patrick J. Wolfe
* uunet!uiucuxc!kailand!pwolfe
* pwolfe@kailand.kai.com
*
* Additions of Xenix,Sun,DOS,VMS and OS2 key handling
* made by Mark Hessling (mark@itc.gu.edu.au)
*
*/
#include <curses.h>
#if !defined(DOS) && !defined(OS2)
#include "getch.h"
#define NORMAL 100
#define ESCAPE 200
#define FKEY 300
int my_getch (winptr)
WINDOW *winptr;
{
int c;
int state = NORMAL;
int fkeycount = 0;
while (1) {
#ifndef VMS
c = wgetch(winptr);
#else
c = keypress();
#endif
switch (state) {
case FKEY:
switch (c) {
/* numeric function keys */
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
fkeycount = (fkeycount * 10) + (c - '0');
break;
case '~':
switch (fkeycount) {
/* Find, Insert Here, Remove, Select, Prev Screen, Next Screen */
case 1: return KEY_Find;
case 2: return KEY_InsertHere;
case 3: return KEY_Remove;
case 4: return KEY_Select;
case 5: return KEY_PrevScreen;
case 6: return KEY_NextScreen;
/* unshifted vt220 function keys */
case 17: case 18: case 19: case 20: case 21:
return KEY_F6 + (fkeycount - 17);
case 23: case 24: case 25: case 26:
return KEY_F11 + (fkeycount - 23);
case 28: case 29:
return KEY_F15 + (fkeycount - 28);
case 31: case 32: case 33: case 34:
return KEY_F17 + (fkeycount - 31);
/* vt220 function keys - control */
case 37: case 38: case 39: case 40: case 41:
return KEY_SF6 + (fkeycount - 37);
case 43: case 44: case 45: case 46:
return KEY_SF11 + (fkeycount - 43);
case 48: case 49:
return KEY_SF15 + (fkeycount - 48);
case 51: case 52: case 53: case 54:
return KEY_SF17 + (fkeycount - 51);
/* shifted tvs922 function keys */
/* case 37: case 38: case 39: case 40: case 41:
case 42: case 43: case 44: case 45: case 46:
case 47: case 48: case 49: case 50: case 51:
return KEY_SF6 + (fkeycount - 37); */
default:
state = NORMAL;
}
break;
case 'A': return KEY_UP;
case 'B': return KEY_DOWN;
case 'C': return KEY_RIGHT;
case 'D': return KEY_LEFT;
case 'M': return KEY_PadEnter;
case 'Z': return KEY_BackTab;
/* Xenix default key mappings */
case 'H': return KEY_HOME;
case 'F': return KEY_END;
case 'L': return KEY_InsertHere;
case 'G': return KEY_NextScrn;
case 'I': return KEY_PrevScrn;
case 'N': return KEY_F2;
case 'O': return KEY_F3;
case 'T': return KEY_F8;
case 'U': return KEY_F9;
case 'V': return KEY_F10;
case 'W': return KEY_F11;
case 'X': return KEY_F12;
/* VT[12]00 PF keys */
case 'P': case 'Q': case 'R': case 'S':
return KEY_PF1 + (c - 'P');
/* VT[12]00 keypad */
case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y':
return KEY_PadComma + (c - 'l');
case 'z':
switch (fkeycount) {
/* SUN F1-F10 */
case 224: case 225: case 226: case 227: case 228:
case 229: case 230: case 231: case 232: case 233:
return KEY_F1 + (fkeycount - 224);
/* SUN S-F1-S-F10 */
case 324: case 325: case 326: case 327: case 328:
case 329: case 330: case 331: case 332: case 333:
return KEY_SF1 + (fkeycount - 324);
case 192: return KEY_F11;
case 193: return KEY_F12;
case 195: return KEY_UNDO;
case 292: return KEY_SF11;
case 293: return KEY_SF12;
case 214: return KEY_HOME;
case 414: return KEY_CHOME;
case 215: return KEY_UP;
case 415: return KEY_CUP;
case 216: return KEY_PrevScrn;
case 416: return KEY_CPGUP;
case 217: return KEY_LEFT;
case 417: return KEY_CLEFT;
case 219: return KEY_RIGHT;
case 419: return KEY_CRIGHT;
case 220: return KEY_END;
case 420: return KEY_CEND;
case 221: return KEY_DOWN;
case 421: return KEY_CDOWN;
case 222: return KEY_NextScrn;
case 422: return KEY_CPGDN;
case 2: return KEY_InsertHere;
default:
state = NORMAL;
}
break;
default:
state = NORMAL;
}
break;
case ESCAPE:
switch (c) {
case 'O':
case '[':
state = FKEY;
fkeycount = 0;
break;
default:
state = NORMAL;
}
break;
default:
switch (c) {
case Escape:
state = ESCAPE;
break;
case CSI:
state = FKEY;
fkeycount = 0;
break;
default:
return (c);
}
}
}
}
#endif
#if defined(DOS) || defined(OS2)
int my_getch (winptr)
WINDOW *winptr;
{
return(wgetch(winptr));
}
#endif
#ifdef VMS
#include iodef
#include descrip
/***********************************************************************/
int keypress()
/***********************************************************************/
{
/*--------------------------- local data ------------------------------*/
struct { long length; char *address; } logical_name;
struct { short status; short length; int remainder; } iosb;
static char kb[] = { "sys$input" };
static int chan;
static char key = 0;
int new_key;
static int first = 1;
int status;
/*--------------------------- processing ------------------------------*/
key = 0;
logical_name.length = strlen (kb);
logical_name.address = kb;
status = sys$assign (&logical_name, &chan, 0, 0);
if (status != 1)
return(-1);
status = SYS$QIOW(0, chan, IO$_READVBLK | IO$M_NOFILTR | IO$M_NOECHO
| IO$M_TIMED, &iosb, 0, 0, &key, 1,600, 0,0, 0, 0);
if (!key)
return (0);
new_key = (int)(unsigned)(key);
status = sys$dassgn (chan);
return (new_key);
}
#endif